package com.topvision.auth.service.impl;

import com.topvision.auth.domain.SysUserAccount;
import com.topvision.auth.repository.SysUserAccountRepository;
import com.topvision.auth.service.SysUserAccountService;
import com.topvision.common.exception.BusinessException;
import com.topvision.common.security.SecurityErrorPrompt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author shengwm
 */
@Service
@Slf4j
public class SysUserAccountServiceImpl implements SysUserAccountService {

    @Autowired
    private SysUserAccountRepository sysUserAccountRepository;
    @Override
    public SysUserAccount findUserAccount(String username) {
        return Optional.ofNullable(sysUserAccountRepository.findOneByAccount(username)).orElseThrow(() -> new BusinessException(SecurityErrorPrompt.SEED_MICRO_SECURITY_STATUS_10001.getValue(), SecurityErrorPrompt.SEED_MICRO_SECURITY_STATUS_10001.getLabel()));
    }

    @Override
    public void save(SysUserAccount sysUserAccount) {
        sysUserAccountRepository.save(sysUserAccount);
    }
}
